\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{myoptions}[2023-04-21 v1.0 for test]

%%本包目前有:
%%字体选项模式（默认方正fz、文泉驿wqy、思源sy、主鸿蒙字体hm)
%%纸张选项模式（默认bighonor：90mm*200mm、honor：72mm*160mm、pad：120mm*160mm、normal：a4paper）
%%背景颜色模式（ebook、eye、white）
%%页眉页脚选项（upfancy、downfancy、rheadfancy、totalfancy、linefancy、clinefancy）
%%首页定制选项（cover)
%%图片包graphicx、加载路径、\mylogo、\tobecontinued、\finished
%%changes包，稍改了下颜色，选项（mychanges)
%%hyperref包，设置了下通用的超链接格式

\RequirePackage{kvoptions}
\RequirePackage{etoolbox}
%\RequirePackage{calc}
\SetupKeyvalOptions{family=gzg,prefix=gzg@,setkeys=\kvsetkeys}
\newcommand{\mekv}[1]{\kvsetkeys{gzg}{#1}}

%%字体模式%%
\DeclareStringOption[fz]{ziti}
\DeclareVoidOption{fz}{\mekv{ziti=fz}}
\DeclareVoidOption{wqy}{\mekv{ziti=wqy}}
\DeclareVoidOption{sy}{\mekv{ziti=sy}}
\DeclareVoidOption{hm}{\mekv{ziti=hm}}

%%纸张模式%%
\DeclareStringOption[bighonor]{shebei}
\DeclareVoidOption{honor}{\mekv{shebei=honor}}
\DeclareVoidOption{pad}{\mekv{shebei=pad}}
\DeclareVoidOption{bighonor}{\mekv{shebei=bighonor}}
\DeclareVoidOption{normal}{\mekv{shebei=normal}}
\DeclareVoidOption{bigshort}{\mekv{shebei=bigshort}}

%%页眉页脚%%
\DeclareStringOption[upfancy]{headfoot}
\DeclareVoidOption{upfancy}{\mekv{headfoot=upfancy}}
\DeclareVoidOption{downfancy}{\mekv{headfoot=downfancy}}
\DeclareVoidOption{totalfancy}{\mekv{headfoot=totalfancy}}
\DeclareVoidOption{linefancy}{\mekv{headfoot=linefancy}}
\DeclareVoidOption{clinefancy}{\mekv{headfoot=clinefancy}}
\DeclareVoidOption{rheadfancy}{\mekv{headfoot=rheadfancy}}

%%背景颜色模式%%
\DeclareStringOption[ebook]{mode}
\DeclareVoidOption{eye}{\mekv{mode=eye}}
\DeclareVoidOption{ebook}{\mekv{mode=ebook}}
\DeclareVoidOption{white}{\mekv{mode=white}}

\DeclareDefaultOption{
%    \PassOptionsToClass{\CurrentOption}{ctexbook}
    \PackageWarning{myoptions}{Unknown option `\CurrentOption'}
}
\ProcessKeyvalOptions*\relax


%%=================背景颜色=================%%
\RequirePackage[table]{xcolor}
\colorlet{coteal}{teal!70!black}
%\colorlet{cored}{red!70!black}
\definecolor{cored}{RGB}{192,63,60}
\colorlet{coorange}{orange!70!white}
\colorlet{cogteal}{teal!70!gray}
\colorlet{cocyan}{cyan!70!black}
\colorlet{cogreen}{green!50!black}
\colorlet{coolive}{olive!70!black}
\colorlet{comagenta}{magenta!70!black}
\colorlet{coblue}{blue!70!black}
\colorlet{coyellow}{yellow!70!lightgray}

\colorlet{cobyellow}{yellow!30!white}
\colorlet{coborange}{orange!20!white}
\colorlet{cobgray}{lightgray!20!white}
\colorlet{cobblue}{blue!10!white}%做底色很不错
\colorlet{cobred}{red!5!white}

\definecolor{eye}{RGB}{199,237,204}%护眼绿
\definecolor{ebook}{RGB}{215,190,150}%棕褐色
\definecolor{xblue}{RGB}{1,126,218}%浅蓝色
\definecolor{kblue}{RGB}{0,65,165}%孔雀蓝
%\definecolor{goldenrod}{RGB}{235,150,25}%
%\definecolor{cyan}{RGB}{0,175,152}%浅青色
%\definecolor{royalblue}{RGB}{39,64,139}%品蓝色
%\definecolor{deepskyblue}{RGB}{0,104,139}%深空蓝
\definecolor{eblue}{RGB}{20,50,104}
\newcommand{\scol}[1]{\colorbox{#1}{\rule{0em}{1ex}\ }\,\textcolor{#1}{#1}}

\ifdefstring{\gzg@mode}{eye}{
    \pagecolor{eye}
    \colorlet{biaoti}{xblue}%设置标题颜色
    \colorlet{main}{cogreen}
    \colorlet{second}{coorange}
    \colorlet{third}{coblue}
}{\relax}
\ifdefstring{\gzg@mode}{ebook}{
    \pagecolor{ebook}
    \colorlet{biaoti}{kblue}%设置标题颜色
    \colorlet{main}{cogreen}
    \colorlet{second}{comagenta}
    \colorlet{third}{cogteal}
}{\relax}
\ifdefstring{\gzg@mode}{white}{
    \pagecolor{white}
    \colorlet{biaoti}{xblue}%设置标题颜色
    \colorlet{main}{cogteal}
    \colorlet{second}{orange}
%    \colorlet{third}{}
    \colorlet{third}{violet!70}
}{\relax}

%%=================字体选项=================%%
\RequirePackage{xeCJKfntef}
%%英文字体
%\setmainfont{DejaVu Serif}
%\setmainfont{TeX Gyre Pagella}
\setmainfont{Noto Serif Light}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}
%%数学字体
%\usepackage{mathspec}
\xeCJKsetup{CJKmath=true}
\setCJKmathfont{FZKai-Z03} 

%%鸿蒙字体+方正字体
\ifdefstring{\gzg@ziti}{hm}{
    \setCJKmainfont[AutoFakeSlant]{HarmonyOS Sans SC}
    \setCJKsansfont[AutoFakeBold,AutoFakeSlant]{方正小标宋简体}
    \setCJKmonofont[AutoFakeBold,AutoFakeSlant]{FZShuSong-Z01}
    \setCJKfamilyfont{zhsong}[AutoFakeBold,AutoFakeSlant]{FZShuSong-Z01}
    \setCJKfamilyfont{zhhei}[AutoFakeBold,AutoFakeSlant]{FZHei-B01}
    \setCJKfamilyfont{zhkai}[AutoFakeBold,AutoFakeSlant]{FZKai-Z03}
    \setCJKfamilyfont{zhfs}[AutoFakeBold,AutoFakeSlant]{FZFangSong-Z02}
    \newcommand*{\songti}{\CJKfamily{zhsong}}% 宋体
    \newcommand*{\heiti}{\CJKfamily{zhhei}}% 黑体
    \newcommand*{\kaishu}{\CJKfamily{zhkai}}% 楷体
    \newcommand*{\fangsong}{\CJKfamily{zhfs}}% 仿宋
    
    \newCJKfontfamily[harmonyos]{\hmos}[AutoFakeBold]{HarmonyOS Sans SC}%鸿蒙字体
}{\relax}
%%方正字体
\ifdefstring{\gzg@ziti}{fz}{
    \setCJKmainfont[AutoFakeBold,AutoFakeSlant]{FZFangSong-Z02}
    \setCJKsansfont[AutoFakeBold,AutoFakeSlant]{FZHei-B01}
    \setCJKmonofont[AutoFakeBold,AutoFakeSlant]{FZShuSong-Z01}
    \setCJKfamilyfont{zhsong}[AutoFakeBold,AutoFakeSlant]{FZShuSong-Z01}
    \setCJKfamilyfont{zhhei}[AutoFakeBold,AutoFakeSlant]{FZHei-B01}
    \setCJKfamilyfont{zhkai}[AutoFakeBold,AutoFakeSlant]{FZKai-Z03}
    \setCJKfamilyfont{zhfs}[AutoFakeBold,AutoFakeSlant]{FZFangSong-Z02}
    \setCJKfamilyfont{zhli}[AutoFakeBold,AutoFakeSlant]{FZLiShu-S01}
    \setCJKfamilyfont{zhxbs}[AutoFakeBold,AutoFakeSlant]{方正小标宋简体}
    \newcommand*{\songti}{\CJKfamily{zhsong}}% 宋体
    \newcommand*{\heiti}{\CJKfamily{zhhei}}% 黑体
    \newcommand*{\kaishu}{\CJKfamily{zhkai}}% 楷体
    \newcommand*{\fangsong}{\CJKfamily{zhfs}}% 仿宋
    \newcommand*{\lishu}{\CJKfamily{zhli}}% 隶书
    \newcommand*{\xiaobiaosong}{\CJKfamily{zhxbs}}%方正小标宋
    %手机默认字体(非方正)
    \setCJKfamilyfont{harmonyos}[AutoFakeBold,AutoFakeSlant]{HarmonyOS Sans SC}
    \newcommand{\harmony}{\CJKfamily{harmonyos}}
}{\relax}

%%文泉驿字体(如果出错，看下是否fontset设置为none了。）
\ifdefstring{\gzg@ziti}{wqy}{
    \setCJKmainfont[AutoFakeBold,AutoFakeSlant]{WenQuanYi Zen Hei}
    \setCJKsansfont[AutoFakeBold,AutoFakeSlant]{WenQuanYi Micro Hei}
    \setCJKmonofont[AutoFakeBold,AutoFakeSlant]{WenQuanYi Micro Hei Mono}
}{\relax}

%思源字体(配置不全）
\ifdefstring{\gzg@ziti}{sy}{
    \setCJKmainfont{Source Han Serif CN}
    [
    UprightFont = *-Regular,
    BoldFont = *-Bold,
    ItalicFont = *-Regular,
    BoldItalicFont = *-Bold
    ]
    \setCJKsansfont{Noto Sans CJK SC}
    [
    UprightFont = *-Regular,
    BoldFont = *-Bold,
    ItalicFont = *-Regular,
    BoldItalicFont = *-Bold
    ]
    \setCJKmonofont{Noto Sans Mono CJK SC}
    [
    UprightFont = *-Regular,
    BoldFont = *-Bold,
    AutoFakeSlant = 0.2
    ]
    \setCJKfamilyfont{zhsong}{Source Han Serif CN}
    [
    UprightFont = *-Regular,
    BoldFont = *-Bold,
    ItalicFont = *-Regular,
    BoldItalicFont = *-Bold
    ]
    \setCJKfamilyfont{zhhei}{Noto Sans CJK SC}
    [
    UprightFont = *-Regular,
    BoldFont = *-Bold,
    ItalicFont = *-Regular,
    BoldItalicFont = *-Bold
    ]
    \setCJKfamilyfont{zhxh}{Noto Sans CJK SC Light}
    \setCJKfamilyfont{zhfs}[AutoFakeBold,AutoFakeSlant]{FangSong}
    \setCJKfamilyfont{zhkai}[AutoFakeBold,AutoFakeSlant]{KaiTi}
    
    \newcommand*{\songti}{\CJKfamily{zhsong}} % 思源宋体
    \newcommand*{\heiti}{\CJKfamily{zhhei}} % 思源黑体
    \newcommand*{\xihei}{\CJKfamily{zhxh}} % 思源细黑
    \newcommand*{\fangsong}{\CJKfamily{zhfs}} % 仿宋
    \newcommand*{\kaishu}{\CJKfamily{zhkai}} % 楷书
}{\relax}


%%=================设备选项=================%%
\RequirePackage{geometry}
\ifdefstring{\gzg@shebei}{honor}{
    \geometry{
        paperwidth=72mm,
        paperheight=160mm,
        hdivide={5mm,,5mm},
        vdivide={1mm,,12mm},
        headsep=1em,
        footskip=1.8em
    }
}{\relax}

\ifdefstring{\gzg@shebei}{pad}{
    \geometry{
        paperwidth=120mm,
        paperheight=160mm,
        hdivide={10mm,,10mm},
        vdivide={12mm,,12mm},
        headsep=1.2em,
        footskip=1.8em
    }
}{\relax}
\ifdefstring{\gzg@shebei}{normal}{
    \geometry{
%        a4paper,
        papersize={210mm,297mm},%{宽,高}
        hdivide={28mm,156mm,},%{左边距,文本宽,右边距}
        vdivide={37mm,225mm,},%{上边距,文本高,下边距}
        footskip=14mm %页脚的位置
    }
    \renewcommand{\normalsize}{\zihao{4}}
    \setlength{\lineskip}{24pt} %行距
}{\relax}
\ifdefstring{\gzg@shebei}{bighonor}{
    \geometry{
        paperwidth=90mm,
        paperheight=200mm,
        hdivide={6mm,,6mm},
        vdivide={12mm,,12mm},
        headsep=1.5em,
        footskip=1.8em
    }
    \renewcommand{\normalsize}{\zihao{4}}
%    \setlength{\lineskip}{24pt} %行距
}{\relax}
\ifdefstring{\gzg@shebei}{bigshort}{
    \geometry{
        paperwidth=90mm,
        paperheight=160mm,
        hdivide={6mm,,6mm},
        vdivide={12mm,,12mm},
        headsep=1.5em,
        footskip=1.8em
    }
    \renewcommand{\normalsize}{\zihao{-4}}
    %    \setlength{\lineskip}{24pt} %行距
}{\relax}
%%================间距设定================%%
%\setlength{\lineskiplimit}{3pt}
%\setlength{\lineskip}{3pt}
\setlength{\parskip}{0ex}
%\linespread{1.5}%行距倍数,缺省的基础行距是1.2倍字号大小
%\setlength{\leftskip}{⟨length⟩}%段落的左缩进
%\setlength{\rightskip}{⟨length⟩}%段落的右缩进
%\setlength{\parindent}{⟨length⟩}%段落的首行缩进




%%=================页眉页脚=================%%
%%如果使用文档类后自定义了纸张大小，最好在其后面用这些页眉页脚命令，否则位置会出问题
\RequirePackage{fancyhdr,lastpage}
\ifdefstring{\gzg@headfoot}{downfancy}{
\fancypagestyle{myfancy}{%
    \fancyhf{}
    \lhead{\itshape\small{\kaishu\rightmark}}
    \rhead{\small{\thepage/\pageref*{LastPage}}}
    \renewcommand{\headrulewidth}{0pt}
}}{\relax}
\ifdefstring{\gzg@headfoot}{upfancy}{
\fancypagestyle{myfancy}{%
    \fancyhf{}
    \lhead{\itshape\small{\kaishu\leftmark}}
    \rhead{\small{\thepage/\pageref*{LastPage}}}
    \renewcommand{\headrulewidth}{0pt}
}}{\relax}
\ifdefstring{\gzg@headfoot}{rheadfancy}{
\fancypagestyle{myfancy}{%
    \fancyhf{}
    %    \lhead{\itshape\small{\kaishu\leftmark}}
    \rhead{\small{\thepage}}
    \renewcommand{\headrulewidth}{0pt}
}}{\relax}
\ifdefstring{\gzg@headfoot}{totalfancy}{
\fancypagestyle{myfancy}{%
    \fancyhf{}
    \cfoot{第\thepage 页\ 共\ \pageref*{LastPage}\ 页}
    \renewcommand{\headrulewidth}{0pt}
}}{\relax}
\ifdefstring{\gzg@headfoot}{linefancy}{
\fancypagestyle{myfancy}{%
    \fancyhf{}
    \fancyfoot[RO,LE]{--\ \thepage\ --\hspace{1em}}
    \renewcommand{\headrulewidth}{0pt}
}}{\relax}
\ifdefstring{\gzg@headfoot}{clinefancy}{
    \fancypagestyle{myfancy}{%
        \fancyhf{}
        \cfoot{--\ \thepage\ --\hspace{1em}}
        \renewcommand{\headrulewidth}{0pt}
}}{\relax}
%%=================一些宏包=================%%
\usepackage[inline]{enumitem}
\setlist{itemsep=0pt,parsep=0pt,topsep=0pt,partopsep=0pt}


%%=================定义changes颜色=================%%
\let\comment\undefined
\RequirePackage{changes}
\DeclareOption{mychanges}{
    \setaddedmarkup{\textcolor{cored}{#1}}
    \sethighlightmarkup{\colorbox{yellow}{#1}}
    \setcommentmarkup{\todo[backgroundcolor=coorange,size=\small]{#1}}
}

\DeclareOption*{\relax}
%\ExecuteOptions{mychanges}
\ProcessOptions*\relax

%可能的图片加载路径
\graphicspath{
    %    {./figure/}
    %    {./figures/}
    {./image/}
    {./images/}
    %    {./graphics/}
    %    {./graphic/}
    {./pictures/}
    {./picture/}
}

%%=================加载图片=================%%
\RequirePackage{graphicx}

\newcommand{\mylogo}[2][0.7]{{\includegraphics[width=#1\textwidth]{#2}}}

%%=================定制首页=================%%
    \makeatletter
    \newcommand{\cover}[1][logo]{%
        \thispagestyle{empty}%这部分是另标题单独占一页
        %	  \vfill
        \ \vskip 4em
        \begin{center}%\leavevmode
            \normalfont
            {\LARGE \heiti\color{cored} \@title\par}%
            \vskip 1em    
            {\Large \kaishu\color{coteal} 
                \begin{tabular}[t]{c}
                    \@author
                \end{tabular}\par}%
            \vskip 1em
            {\Large \textcolor{cogreen}{\@date}\par}
            \ifdefempty{\@date}{\relax}{\vskip 2em}%如果date不是空的，就下移2em
%            \includegraphics[width=0.7\textwidth]{logo}
            \mylogo[0.7]{#1}
            %		{\fontsize{54pt}{10em}\color[RGB]{39,64,139}{\[\mathwitch*\]}}
        \end{center}%
        %  \vfill
        %  \cleardoublepage  %结束当前页，下一页从奇数页开始
        \newpage
    }
    %\setcounter{footnote}{0}%
    %\global\let\thanks\relax
    %\global\let\maketitle\relax
    %\global\let\@thanks\@empty
    %\global\let\@author\@empty
    %\global\let\@date\@empty
    %\global\let\@title\@empty
    %\global\let\title\relax
    %\global\let\author\relax
    %\global\let\date\relax
    %\global\let\and\relax
    \makeatother



%%=================通用设置=================%%


%%================小小的定义================%%
\newcommand{\charef}[1]{第\ref{#1}章}
\newcommand{\secref}[1]{第\ref{#1}节}
\newcommand{\pref}[1]{第\pageref{#1}页}
\newcommand{\fref}[1]{图\ref{#1}}
\newcommand{\tref}[1]{表\ref{#1}}
\newcommand{\cmmd}[1]{\fbox{\texttt{\char92{}#1}}}
\newcommand{\myarg}[1]{{\textcolor{violet}{<\emph{#1}>}}}
\newenvironment{Quote}[1][cogreen]{\begin{quotation}\itshape\kaishu\color{#1}}{\end{quotation}}

\RequirePackage{hyperref}    
\AtEndPreamble{%保证在导言区最后调用
\hypersetup{
    unicode,
    bookmarksopen=true,
    %    bookmarksopenlevel=1,
    bookmarksnumbered=true,
    pdfproducer=xelatex,
    pdfcreator=texstudio,
    colorlinks,
    linkcolor=cored,
    citecolor=cored,
    anchorcolor=comagenta,
    urlcolor=cogreen,
    pdfstartview=FitH,
%    pdfborder={0 0 0},
    linktoc=all,
    linktocpage,
    pdfdisplaydoctitle,
    %breaklinks,
%    pagebackref,%此参数实现参考文献与正文的双向链接 
%    backref=page,%同上
}
}